<?php
/**
 * Created by PhpStorm.
 * User: liang
 * Email:1050187159@qq.com
 * Date: 2018/8/19
 * Time: 22:22
 */
namespace Home\Controller;


class InvestsController extends BaseController
{
    public function index()
    {
        if (!IS_POST) {
            $option_id = I('get.id');
            $Option = D('Option');
            $option = $Option->where(array(
                'id' => array('eq',$option_id),
                'is_show' => array('neq',0),
                'navigator_id' => array('eq',6)
            ))->find();
            if (empty($option)) {
                $this->_empty();
            }
            $option['description'] = htmlspecialchars_decode($option['description']);

            $Invest = D('Invest');
            //查询满足要求的总记录数
            $count = $Invest->where(array('is_show'=>array('eq',1)))->count();
            //实例化分页类 传入总记录数和每页显示的记录数(10)
            $Page = new \Think\Page($count,10);
            $Page->setConfig('next',C('PAGE_CONFIG.next'));
            $Page->setConfig('prev',C('PAGE_CONFIG.prev'));
            $Page->setConfig('last',C('PAGE_CONFIG.last'));
            $Page->setConfig('first',C('PAGE_CONFIG.first'));
            $Page->lastSuffix=C('PAGE_CONFIG.lastSuffix');//在此设置一行
            $show = $Page->show();// 分页显示输出
            //进行分页数据查询 注意limit方法的参数要使用Page类的属性
            $invests = $Invest->where(array('is_show'=>array('eq',1)))->order('sort desc')->limit($Page->firstRow.','.$Page->listRows)->select();

            foreach ($invests as $key => $invest) {
                $invests[$key]['content'] = msubstr(strip_tags(htmlspecialchars_decode($invest['content'])), 0, 120);
            }

            $this->assign(array(
                // 赋值数据集
                'invests' => $invests,
                // 赋值分页输出
                'show' => $show
            ));


            $this->assign(array(
                'nav' => $option
            ));
            $this->display('web/Invests/index');
        }
    }

    //新闻详情页
    public function detail()
    {
        $id = I('get.id');
        $Invest = D('Invest');
        $count = $Invest->where(array('id'=>array('eq',$id)))->count();
        if (!$count) {
            $this->_empty();
            exit;
        }
        $invest = $Invest->where(array('id'=>array('eq',$id)))->find();
        $invest['content'] = htmlspecialchars_decode($invest['content']);
        $this->assign(array(
            'invest'  => $invest
        ));
        if ($this->isMobile()) {

        } else {
            $this->display('web/Invests/article');
        }
    }




}

